<?php
/* wwwschool project

Copyright (C) 2009  Phillip Aldridge
Email : info@imi21.com
Web site http://www.imi21.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/**
 *  File : listCourseLessons.php
 *  called only via ajax 
 *  List all the modules in the lesson with  in the table 'lessons'
 *  Requires a course id 
 */
 
require '../../includes/classes/WS3tableview.php';
require '../../includes/classes/WS3lesson.php';

$message="";

$lesson = new WS3_Lesson();
if ( $lesson->setLessonID( $id ) )
{

  $table=new WS3_TableView('main',400);
  $table->setTitle( 'Listing Modules in Lesson '.$lesson->LessonName() );
  $table->addColumnTH('Position');
  $table->addColumnTH('Name');
  $table->addColumnMove(true,'Module2Lesson');
  $table->addColumnDelete(true,'ModuleLesson');
  $table->setAlternativeRows(true);
  $table->setInfoRow(true);

  $dbModules=new WS3_Database();
  $q="SELECT ml.position AS p, ml.id AS mlid , m.* FROM `module2lesson` AS ml, `module` AS m
  WHERE ml.lesson_id='".$lesson->LessonID()."' AND m.id=ml.module_id
  ORDER BY ml.position";
  

  if ($dbModules->query($q))
  {
    $count =$dbModules->numberRows();
    while ( $dbModules->nextRecord() )
    {
       $table->addRow( $dbModules->f('mlid'), array(
       'Position' => $dbModules->f('p'), 
       'Name' => javaSafeString( $dbModules->f('name') )
        ));
    } 
    $table->addToInfoRow("<p>Count = $count </p>");
    echo $table->display();
    $message="Listing";
  }else{
    $message="Error : Empty list";
  }
 }else{
  $message="Error : ID not found";
}


require '../../includes/menus/topLessonModules.php';
$menu=javaSafeString($menu);
echo "document.getElementById('topmenu').innerHTML='$menu';";

echo "document.getElementById('messages').innerHTML='$message';";

if (W3DEBUG)  $debug=new WS3_Debug();

?>
